package com.minivision.sdktestdemo.controler.ui.viewpager;

import android.content.Context;
import android.support.v4.app.Fragment;

import com.minivision.sdktestdemo.controler.ui.list.AlbumListControler;
import com.minivision.sdktestdemo.controler.ui.list.DirPathListControler;
import com.minivision.sdktestdemo.controler.ui.list.SingerListControler;
import com.minivision.sdktestdemo.model.MusicProvider;
import com.minivision.sdktestdemo.ui.ClassfiedInfoFragment;
import com.minivision.sdktestdemo.ui.MusicListFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by devtang on 2016/4/7.
 */
public class MusicNavControler {
    public static final String PARAM1 = "title";
    public static final String PARAM2 = "other";
    public static final String TITLE_PRE = "music_tab";
    private List<Fragment> mList;
    private Context mContext;

    public MusicNavControler(Context context) {
        mContext = context;
        mList = new ArrayList<Fragment>();
        mList.add(MusicListFragment.newInstance(TITLE_PRE + 1, false));
        ((MusicListFragment) mList.get(0)).setListBean(MusicProvider.getInstance(context).getList());
        mList.add(ClassfiedInfoFragment.newInstance(TITLE_PRE + 2, SingerListControler.class));
        mList.add(ClassfiedInfoFragment.newInstance(TITLE_PRE + 3, AlbumListControler.class));
        mList.add(ClassfiedInfoFragment.newInstance(TITLE_PRE + 4, DirPathListControler.class));
    }

    public List<Fragment> getViewPagerFragments() {
        return mList;
    }

    public Fragment getViewPagerFragment(int position) {
        return mList.get(position);
    }

    public String getTitle(int position) {
        //先获取标题的ID字符串
        String id = mList.get(position).getArguments().get(PARAM1).toString();
        //然后利用反射获取具体的标题栏
        return mContext.getString(mContext.getResources().getIdentifier(id, "string", mContext.getPackageName()));
    }

    public int getViewPagerSize() {
        return mList.size();
    }
}
